<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>抖音直播助手</title>
    </head>
    <body>
        <div style="text-align: center">
            <h1>抖音直播助手</h1>
        </div>
        <div>
            <span>请选择手机</span>
            <br/>
            <select id="mobileSelect">
                <option th:each="udid, stat : ${udids}" th:value="${udid}" th:text="${udid} + '(' + ${stat.count} + ')'"></option>
            </select>
        </div>
        <div>
            <b><span>手动执行</span></b>
            <br/>
            点击坐标(
            <input type="text" id="clickX" style="width: 40px;">
            ,
            <input type="text" id="clickY" style="width: 40px;">
            )
            <input type="text" id="clickTimes" style="width: 60px;">
            次，每次间隔
            <input type="text" id="clickTerm" style="width: 60px;">
                   毫秒
            <button onclick="multiClick()">执行</button>
            <br />
            <div>
                爱心达人:(1120,2627)
            </div>
            <br />
            <b><span>发送文字内容</span></b>
            <br />
            输入框坐标(
            <input type="text" id="msgInputX" style="width: 40px;" value="180">
            ,
            <input type="text" id="msgInputY" style="width: 40px;" value="2263">
            ),发送按钮坐标(
            <input type="text" id="msgSendX" style="width: 40px;" value="936">
            ,
            <input type="text" id="msgSendY" style="width: 40px;" value="2042">
            )
            <br />
            <br />
            <textarea cols="50" rows="3" id="contentId"></textarea>
            <button onclick="sendMsg()">执行</button>
        </div>
    </body>
    <script>
        // 循环执行点击
        function multiClick() {
            let x = document.getElementById('clickX').value;
            let y = document.getElementById('clickY').value;
            let times = document.getElementById('clickTimes').value;
            let term = document.getElementById('clickTerm').value;
            let udid = document.getElementById('mobileSelect').value;
            // ajax请求
            let xhr = new XMLHttpRequest();
            xhr.open('post', '/click');
            xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");
            xhr.send('x=' + x + '&y=' + y + '&times=' + times + '&term=' + term + '&udid=' + udid);
            xhr.onreadystatechange = function () {
                if (xhr.status === 200) {
                    console.log('点击成功');
                }
            }
        }
        // 发送文字内容
        function sendMsg() {
            // 获取坐标
            let msgInputX = document.getElementById('msgInputX').value;
            let msgInputY = document.getElementById('msgInputY').value;
            let msgSendX = document.getElementById('msgSendX').value;
            let msgSendY = document.getElementById('msgSendY').value;
            let content = document.getElementById('contentId').value;
            let udid = document.getElementById('mobileSelect').value;

            let xhr = new XMLHttpRequest();
            xhr.open('post', '/sendMsg');
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xhr.send('udid=' + udid + '&content=' + content + '&msgInputX=' + msgInputX + '&msgInputY=' + msgInputY + '&msgSendX=' + msgSendX + '&msgSendY=' + msgSendY);
            xhr.onreadystatechange = function () {
                if (xhr.status === 200) {
                    console.log('发送消息成功');
                }
            }
        }
    </script>
</html>